package com.jeedlelabs.tubess;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class VideoGridViewAdapter extends ArrayAdapter<Item> {

	private Context context;
	private int layoutResourceId;
	private ArrayList<Item> data = new ArrayList<Item>();
	
	public VideoGridViewAdapter(Context context, int layout,ArrayList<Item> data)
	{
		super(context,layout,data);
		this.layoutResourceId = layout;
		this.context = context;
		this.data = data;

	}
	
	@Override
	public View getView(int position,View ImageView,ViewGroup parent)
	{
		View row = ImageView;
		RecordHolder holder = null;
		Item item = data.get(position);
		
		if (row == null)
		{
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId,parent,false);
			holder = new RecordHolder();
			holder.textView = (TextView) row.findViewById(R.id.videoTitle);
			holder.imageView = (ImageView) row.findViewById(R.id.videoThumb);
			row.setTag(holder);		
		}
		else
		{
			holder = (RecordHolder) row.getTag();
		}
		
		holder.textView.setText(item.getTitle());
		holder.imageView.setImageBitmap(item.getImage());
	    

		return row;
	}
	
	static class RecordHolder{
		TextView textView;
		ImageView imageView;
	}
}
